package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.SftMonthCheck;
import com.ruoyi.bussiness.service.ISftMonthCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月检信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/checkM")
public class SftMonthCheckController extends BaseController
{
    private String prefix = "bussiness/checkM";

    @Autowired
    private ISftMonthCheckService sftMonthCheckService;

    @RequiresPermissions("bussiness:checkM:view")
    @GetMapping()
    public String checkM()
    {
        return prefix + "/checkM";
    }

    /**
     * 查询月检信息列表
     */
    @RequiresPermissions("bussiness:checkM:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SftMonthCheck sftMonthCheck)
    {
        startPage();
        List<SftMonthCheck> list = sftMonthCheckService.selectSftMonthCheckList(sftMonthCheck);
        return getDataTable(list);
    }

    /**
     * 导出月检信息列表
     */
    @RequiresPermissions("bussiness:checkM:export")
    @Log(title = "月检信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SftMonthCheck sftMonthCheck)
    {
        List<SftMonthCheck> list = sftMonthCheckService.selectSftMonthCheckList(sftMonthCheck);
        ExcelUtil<SftMonthCheck> util = new ExcelUtil<SftMonthCheck>(SftMonthCheck.class);
        return util.exportExcel(list, "月检信息数据");
    }

    /**
     * 新增月检信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存月检信息
     */
    @RequiresPermissions("bussiness:checkM:add")
    @Log(title = "月检信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SftMonthCheck sftMonthCheck)
    {
        return toAjax(sftMonthCheckService.insertSftMonthCheck(sftMonthCheck));
    }

    /**
     * 修改月检信息
     */
    @RequiresPermissions("bussiness:checkM:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SftMonthCheck sftMonthCheck = sftMonthCheckService.selectSftMonthCheckById(id);
        mmap.put("sftMonthCheck", sftMonthCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存月检信息
     */
    @RequiresPermissions("bussiness:checkM:edit")
    @Log(title = "月检信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SftMonthCheck sftMonthCheck)
    {
        return toAjax(sftMonthCheckService.updateSftMonthCheck(sftMonthCheck));
    }

    /**
     * 删除月检信息
     */
    @RequiresPermissions("bussiness:checkM:remove")
    @Log(title = "月检信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sftMonthCheckService.deleteSftMonthCheckByIds(ids));
    }
}
